#region Copyright & License
/* Tyng.Data
 * Copyright (c) 2007, Paul Tyng, All rights reserved.
 * Code licensed under the BSD License:
 * http://www.opensource.org/licenses/bsd-license.php
 * Downloaded from: http://code.google.com/p/tyngdata/
*/
#endregion

using System;
using System.Collections;
using System.Data;

namespace Tyng.Data
{
	/// <summary>
	/// A basic DataRecord to handle fixed length records with fields at specific locations.
	/// Typically this class should be inherited for each record type you intend to support.
	/// </summary>
	public class FixedLengthDataRecord : FieldDataRecord
	{
		private object[] _values;
		
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="record">Character data of the record</param>
		/// <param name="fields">Array of field definitions</param>
		public FixedLengthDataRecord(char[] record, FixedLengthField[] fields) : base(fields)
		{
			_values = new object[fields.Length];
	
			//Step thru each field
			for (int k = 0; k < fields.Length; k++)
			{
				int fieldPosition = fields[k].Start;
				int fieldLength = fields[k].Length;

				_values[k] = fields[k].ExtractValue(record);
			}
		}

		/// <summary>
		/// Gets the value of the specified column
		/// </summary>
		/// <param name="i">Ordinal of the column</param>
		/// <returns>Typed value</returns>
		protected override object GetValue(int i)
		{
			return _values[i];
		}
	}		

}
